﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;

namespace Manyor.Net
{
    public class SocketSender
    {
        #region -- Private --
        private const int REMOTE_PORT = 4021;
        private const int LOCAL_PORT = 4020;
        private IPEndPoint ipep;//= new IPEndPoint(IPAddress.Parse("127.0.0.1"), 6001);
        private Socket clientSocket;//= new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        #endregion
        
        /// <summary>
        /// 
        /// </summary>
        public SocketSender()
        {
            ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), REMOTE_PORT);
            clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            clientSocket.Bind(new IPEndPoint(IPAddress.Parse("127.0.0.1"), LOCAL_PORT));
            try
            {
                clientSocket.Connect(ipep);    
            
            }
            catch (Exception e)
            {
               
            }
        }

        public void SendString()
        {
            byte[] bytes=new byte[1024];
            bytes = Encoding.ASCII.GetBytes(DateTime.Now.Millisecond.ToString());           
            clientSocket.Send(bytes, bytes.Length, SocketFlags.None);
        }
    }
}
